﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TorchView.GameContent.Effects;
using System.Windows.Input;
using TorchView.Composition;
using System.Windows;
using TorchView.Windows;
using TorchView.GameContent.Affixes;
using TorchView.SharedStashEditor.Helpers;
using TorchView.SharedStashEditor.Models;

namespace TorchView.SharedStashEditor.ViewModels
{
    public class AddAffixViewModel : DependencyObject, IAddAffixViewModel
    {
        private ItemViewModel _item;
        private ItemCollection _collection;

        public AddAffixViewModel(IDialogView<IAddAffixViewModel> view)
        {
            View = view;
            view.Model = this;
            _collection = ItemCollection.DefaultCollection;
            CancelCommand = new DirectCommand(o => { View.DialogResult = false; View.Close(); });
            OKCommand = new DirectCommand(o => { View.DialogResult = true; View.Close(); });
        }

        public void Init(ItemViewModel item)
        {
            _item = item;
            long itemId = item.InnerItem.ItemModelID;
            string itemType = _collection[itemId].UnitType;
            AffixList = AffixItemList.DefaultList.GetListByType(itemType);
        }

        public static readonly DependencyProperty ItemIdProperty =
                DependencyProperty.Register("effect", typeof(TorchView.Game.Effect), typeof(AddAffixViewModel), new UIPropertyMetadata(null));

        public IDialogView<IAddAffixViewModel> View { get; private set; }
        public ICommand CancelCommand { get; private set; }
        public ICommand OKCommand { get; private set; }
        public List<Affix> AffixList { get; private set; }
        public ItemViewModel Item { get; set; }
        public Affix SelectedAffix { get; set; }

        public TorchView.Game.Effect effect 
        {
            get { return (TorchView.Game.Effect)GetValue(ItemIdProperty); }
            set { SetValue(ItemIdProperty, value); }
        }
    }
}
